package org.springblade.modules.admin.entity;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import org.springblade.modules.admin.vo.elevator.ElevatorFloorVo;
import org.springblade.modules.admin.vo.parts.PartWordUrlVo;

/**
 * 电梯信息
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName(value = "blade_elevator", autoResultMap = true)
public class Elevator extends TenantEntity {
	/**
	 * 设备id(对接梯联网设备）
	 */
	@TableField(value = "device_id")
	private String deviceId;

	/**
	 * 栋号
	 */
	@TableField(value = "block")
	private String block;

	/**
	 * 自定义单位 例如 栋，座
	 */
	@TableField(value = "block_name")
	private String blockName;

	/**
	 * 单元号
	 */
	@TableField(value = "unit")
	private String unit;

	/**
	 * 自定义单位 例如 单元
	 */
	@TableField(value = "unit_name")
	private String unitName;

	/**
	 * 梯号
	 */
	@TableField(value = "num")
	private Integer num;

	/**
	 * 层数
	 */
	@TableField(value = "`floor`")
	private String floor;

	/**
	 * 品牌id
	 */
	@JsonSerialize(using = ToStringSerializer.class)
	@TableField(value = "brand_id", updateStrategy = FieldStrategy.IGNORED, insertStrategy = FieldStrategy.IGNORED)
	private Long brandId;

	/**
	 * 品牌型号id
	 */
	@TableField(value = "brand_v_id", updateStrategy = FieldStrategy.IGNORED, insertStrategy = FieldStrategy.IGNORED)
	private Long brandVId;

	/**
	 * 品牌型号系列id
	 */
	@TableField(value = "brand_v_sku_id", updateStrategy = FieldStrategy.IGNORED, insertStrategy = FieldStrategy.IGNORED)
	private Long brandVSkuId;

	/**
	 * 品牌名称
	 */
	@TableField(value = "brand_name")
	private String brandName;

	/**
	 * 系列名称
	 */
	@TableField(value = "series_name")
	private String seriesName;

	/**
	 * 型号名称
	 */
	@TableField(value = "type_name")
	private String typeName;

	/**
	 * 电梯年限
	 */
	@TableField(value = "elevator_year")
	private Integer elevatorYear;

	/**
	 * 电梯年审时间
	 */
	@TableField(value = "elevator_audit")
	private String elevatorAudit;

	/**
	 * 楼盘id
	 */
	@TableField(value = "building_id")
	private Long buildingId;

	/**
	 * 模板id
	 */
	@TableField(value = "template_id", updateStrategy = FieldStrategy.IGNORED, insertStrategy = FieldStrategy.IGNORED)
	private Long templateId;

	/**
	 * 模板关联id集合
	 */
	@TableField(value = "rele_ids", updateStrategy = FieldStrategy.IGNORED, insertStrategy = FieldStrategy.IGNORED)
	private String releIds;

	/**
	 * 模板关联id集合
	 */
	@TableField(value = "private_num", updateStrategy = FieldStrategy.IGNORED, insertStrategy = FieldStrategy.IGNORED)
	private String privateNum;

	/**
	 * 小程序码
	 */
	@TableField(value = "wx_app_code_url")
	private String wxAppCodeUrl;

	/**
	 * 停梯状态： 1-正常 2-停梯
	 */
	@TableField(value = "is_stop")
	private Integer isStop;

	/**
	 * 1:非年审，2:年审
	 */
	@TableField(value = "audit_type")
	private Integer auditType;

	/**
	 * 来源类型 0-平台, 1-维保租户, 2-物业租户
	 */
	@TableField(value = "source_type")
	private Integer sourceType;

	/**
	 * 创建租户id
	 */
	@TableField(value = "source_tenant_id")
	private String sourceTenantId;

	/**
	 * 创建租户名称
	 */
	@TableField(value = "source_tenant_name")
	private String sourceTenantName;

	/**
	 * 创建用户名称
	 */
	@TableField(value = "source_user_name")
	private String sourceUserName;

	/**
	 * 1:表示信息齐全
	 * 0:表示电梯信息不齐全
	 */
	@TableField(value = "is_complete")
	private Boolean isComplete;

	/**
	 * 用户项目id
	 */
	@TableField(exist = false)
	private Long buildingUserId;


	@ApiModelProperty("楼栋id")
	private Long floorElevatorId;


	/**
	 * 电梯名称搜索
	 */
	@TableField(exist = false)
	private String elevatorName;

	@ApiModelProperty("维保-服务电话")
	private String wbPhone;

	@ApiModelProperty("维保-服务电话贴纸")
	@TableField(typeHandler = JacksonTypeHandler.class)
	private List<PartWordUrlVo> wbPhoneImg;

	@ApiModelProperty("维保-更新时间")
	private Date wbPhoneImgDate = new Date();

	@ApiModelProperty("保险-标致url")
	@TableField(typeHandler = JacksonTypeHandler.class)
	private List<PartWordUrlVo> bxExtUrl;

	@ApiModelProperty("保险-标致url")
	private Date bxExtUrlDate = new Date();

	@ApiModelProperty("保险公司名称")
	private  Long bxCompanyId;

	@ApiModelProperty("保险公司到期时间")
	private  Date bxCompanyEndDate;

	@ApiModelProperty("维保-标致附件url")
	@TableField(typeHandler = JacksonTypeHandler.class)
	private List<PartWordUrlVo> wbExtUrl;

	@ApiModelProperty("维保-标致附件url更新时间")
	private Date wbExtUrlDate = new Date();


	@ApiModelProperty("层信息")
	@TableField(typeHandler = JacksonTypeHandler.class)
	private List<ElevatorFloorVo> floorTier;

	@ApiModelProperty("站信息")
	@TableField(typeHandler = JacksonTypeHandler.class)
	private List<ElevatorFloorVo> floorPlatforms;

	@ApiModelProperty("门信息")
	@TableField(typeHandler = JacksonTypeHandler.class)
	private List<ElevatorFloorVo> floorDoors;

	@ApiModelProperty("安装单位")
	private String azUnitName;

	@ApiModelProperty("安装监督检验日期")
	private String azCheckDate;

	@ApiModelProperty("安装单位启用日期")
	private Date azCheckBeginDate;

	@ApiModelProperty("改装单位名称")
	private String gzUnitName;

	@ApiModelProperty("改造监督检验日期")
	private String gzCheckDate;

	@ApiModelProperty("改装单位名称")
	private String dxUnitName;

	@ApiModelProperty("改造监督检验日期")
	private String dxCheckDate;

	@ApiModelProperty("类型位置完整度")
	private BigDecimal lwIntact;

	@ApiModelProperty("结构完整度")
	private BigDecimal jgIntact;

	@ApiModelProperty("维保完整度")
	private BigDecimal wbIntact;

	@ApiModelProperty("保险完整度")
	private BigDecimal bxIntact;

	@ApiModelProperty("设备技术完整度")
	private BigDecimal sbJsIntact;

	@ApiModelProperty("设备注册完整度")
	private BigDecimal sbZcIntact;

	@ApiModelProperty("出厂完整度")
	private BigDecimal ccIntact;

	@ApiModelProperty("使用完整度")
	private BigDecimal syIntact;

	@ApiModelProperty("安装完整度")
	private BigDecimal azIntact;

	@ApiModelProperty("梯无忧完整度")
	private BigDecimal twyIntact;

	@ApiModelProperty("合同第一次的来源状态1:散梯2:新接3:重夺4:安装,5:其它")
	private Integer firstContractStatus;

	@ApiModelProperty("合同审核状态1:审核通过0或者空表示没有审核")
	private Integer contractPassStatus;

	@ApiModelProperty("电梯ids")
	@TableField(exist = false)
	private String elevatorIds;

	@ApiModelProperty("该电梯是否存在问题1:存在0:不存在")
	private Integer isQuestion;

	@ApiModelProperty("该电梯是否存在存档1:存在0:不存在")
	private Integer isGap;

	@ApiModelProperty("重夺状态 1:重夺2:未重夺3:--")
	private Integer regainStatus;

	@ApiModelProperty("电梯ids")
	@TableField(exist = false)
	private List<Long> ids;

	/**
	 * 2025-08新增来源描述字段
	 */
	@TableField(value = "source_desc")
	private String sourceDesc;

	@ApiModelProperty("电梯来源: -1 无状态1:安装2:新接")
	private String sourceStatus;

	@ApiModelProperty("电梯生命周期")
	private Integer lifeStatus;


	public void setElevatorIds(String elevatorIds) {
		this.elevatorIds = elevatorIds;
		if (StrUtil.isNotEmpty(elevatorIds)) {
			List<Long> ids = new ArrayList<>(16);
			String[] split = elevatorIds.split(",");
			for (String str : split) {
				ids.add(Convert.toLong(str));
			}
			this.ids = ids;
		}
	}
}
